<template>
  <div>
    <el-form :model="form" label-width="auto" inline>
      <el-form-item label="入库时间:">
        <el-date-picker v-model="times" type="datetimerange" start-placeholder="开始时间" value-format="x"
          end-placeholder="结束时间" time-format="A hh:mm:ss" />
      </el-form-item>
      <el-form-item label="选择仓库:" v-if="store.productPurchaseStoragesearchWarehouseDicswArr">
        <el-select v-model="form.warehouseId">
          <el-option label="全部" :value="0"></el-option>
          <el-option :label="item.value" :value="item.key"
            v-for="item in store.productPurchaseStoragesearchWarehouseDicswArr" :key="item.key"
            @click="setPrdDic(item)" />
        </el-select>
      </el-form-item>
      <el-form-item label="货主：:">
        <el-select v-model="form.warehouseLocationId">
          <el-option label="全部" :value="0"></el-option>
          <el-option :label="item.value" :value="item.key" v-for="item in warehouseLocationDicList" :key="item.key" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">搜索</el-button>
      </el-form-item>
    </el-form>
  </div>
  <div class="table">
    <el-table ref="multipleTableRef" :data="tableData" style="width: 100%" @selection-change="handleSelectionChange"
      border>
      <el-table-column type="selection" width="55" />
      <el-table-column label="仓库">
        <template #default="scope">{{ scope.row.warehouseName }}</template>
      </el-table-column>
      <el-table-column label="货主" width="180">
        <div>--</div>
      </el-table-column>
      <el-table-column label="入库时间">
        <template #default="scope">{{ scope.row.storageTime }}</template>
      </el-table-column>
      <el-table-column label="入库批次号" width="180">
        <template #default="scope">{{ scope.row.inboundBatchesCode }}</template>
      </el-table-column>
      <el-table-column label="入库数量" width="180">
        <template #default="scope">{{ scope.row.storageNum }}</template>
      </el-table-column>
      <el-table-column label="货区" width="180">
        <template #default="scope">{{
      JSON.parse(scope.row.storageWarehouseArea) ?
        JSON.parse(scope.row.storageWarehouseArea).warehouseAreaData[0].name : ''
    }}</template>
      </el-table-column>
      <el-table-column label="库位" width="180">
        <template #default="scope">{{
      JSON.parse(scope.row.storageWarehouseLocation) ?
        JSON.parse(scope.row.storageWarehouseLocation).warehouseLocationData[0].name : ''
    }}</template>
      </el-table-column>
      <el-table-column label="商品信息" width="180">
        <template #default="scope">{{ JSON.parse(scope.row.storageWarehouseLocation) ?
      JSON.parse(scope.row.storageWarehouseLocation).warehouseLocationData[0].skuInfo : '' }}</template>
      </el-table-column>
      <!-- <el-table-column label="操作" width="180">
        <template #default="scope">
          <el-button link type="primary" size="small" @click.prevent="inHouse(scope.row)">
            入库完成
          </el-button>
        </template>
      </el-table-column> -->
    </el-table>
  </div>
  <div class="page">
    <el-pagination v-model:current-page="currentPage4" v-model:page-size="pageSize4" :page-sizes="[10, 50, 100]"
      layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handleSizeChange"
      @current-change="handleCurrentChange" />
  </div>
  <div>
    <el-dialog v-model="dialogVisibles" title="调换库位" width="600">
      <span>
        <div ref="NUMDom" v-for="(item, index) in    numsKey   " :key='index'>
          库位号：<el-select v-model="warehouseLocationSelectId[index]">
            <el-option :label="item.value" :value="item.key" v-for="item in dialogVisiblesHOuse" :key="item.key" />
          </el-select>
          数量:<el-input v-model="numsKeyObj[index]" type="number" style="width: 200px;" /><el-icon
            @click="upNum(NUMDom)">
            <Plus />
          </el-icon><el-icon @click="downNum" style="margin-left: 20px;">
            <Minus />
          </el-icon>
        </div>
      </span>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="dialogVisibles = false">取消</el-button>
          <el-button type="primary" @click="submintDialog">
            确定
          </el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref, onBeforeMount } from 'vue'
import { productPurchaseStoragelist } from '@/api/index'
import { useAlertsStore } from '@/store/index'
// import { ElMessage } from 'element-plus'
// import { ElMessageBox, ElMessage } from 'element-plus'
const store = useAlertsStore()
// do not use same name with ref
const form = ref({
  storageTimeStart: '',
  storageTimeEnd: '',
  warehouseId: 0,
  warehouseLocationId: 0,
  inboundBatchesCode: '',
  trackingNumbers: [],
  storageStatus: 3,
  pageSize: 10,
  pageNum: 1
})
const trackingNumbers = ref('')
const times = ref('')
const tableData = ref([])
onBeforeMount(() => {
  store.productPurchaseStoragesearchWarehouseDicswBtn()
  // console.log('store.productPurchaseStoragesearchWarehouseDicswArr')
  // console.log(store.productPurchaseStoragesearchWarehouseDicswArr)
})
const onSubmit = () => {
  console.log('submit!')
  getList()
}
const getList = () => {
  if (trackingNumbers.value) {
    // removeNonCommaCharacters(trackingNumbers.value)
    form.value.trackingNumbers = trackingNumbers.value.split(',')
  } else {
    form.value.trackingNumbers = []
  }
  if (times.value) {
    form.value.storageTimeStart = times.value[0]
    form.value.storageTimeEnd = times.value[1]
  } else {
    form.value.storageTimeStart = ''
    form.value.storageTimeEnd = ''
  }
  productPurchaseStoragelist(form.value).then(res => {
    const { data: { data } } = res
    total.value = data.total
    tableData.value = data.list
  })
}
// 分页
const currentPage4 = ref(1)
const pageSize4 = ref(10)
const total = ref(0)
const handleSizeChange = (val) => {
  console.log(`${val} items per page`)
  form.value.pageSize = val
  getList()
}
const handleCurrentChange = (val) => {
  console.log(`current page: ${val}`)
  form.value.pageNum = val
  getList()
}

// table
const multipleSelection = ref([])
const handleSelectionChange = (val) => {
  multipleSelection.value = val
}
const warehouseLocationDicList = ref('')
const setPrdDic = (item) => {
  warehouseLocationDicList.value = item.warehouseLocationDicList
  // console.log(item.warehouseLocationDicList)
}

</script>

<style lang='less' scoped></style>
